package com.freshcity.upload
{
	import com.freshcity.upload.event.UploadEvent;
	
	import flash.display.BitmapData;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.ByteArray;
	import flash.net.*;
	import flash.system.LoaderContext;
	
	public class AvatarModel extends EventDispatcher
	{
		public function AvatarModel(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		
		public function set bmd(arg1:BitmapData):void
		{
			this._bmd = arg1;
			this.dispatchEvent(new UploadEvent(UploadEvent.IMAGE_CHANGE));
			return;
		}
		
		public function set initBmd(arg1:BitmapData):void
		{
			this._bmd = arg1;
			this.dispatchEvent(new UploadEvent(UploadEvent.IMAGE_INIT));
			return;
		}
		
		public function get bmd():BitmapData
		{
			return this._bmd;
		}
		
		public function get type():int
		{
			return this._type;
		}
		
		public function set type(arg1:int):void
		{
			this._type = arg1;
			return;
		}
		
		public function get imgData():ByteArray
		{
			return this._imgData;
		}
		
		public function set imgData(arg1:ByteArray):void
		{
			this._imgData = arg1;
			return;
		}
		
		public function loaderPic(arg1:String):void
		{
			var loc1:*=new flash.net.URLRequest(arg1);
			var loc2:*=new flash.display.Loader();
			var loc3:*=new flash.system.LoaderContext(true);
			loc2.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, this.initPicHandler);
			loc2.contentLoaderInfo.addEventListener(flash.events.IOErrorEvent.IO_ERROR, this.errorHandler);
			loc2.load(loc1, loc3);
			return;
		}
		
		private function initPicHandler(arg1:flash.events.Event):void
		{
			var loc1:*=arg1.target as flash.display.LoaderInfo;
			loc1.removeEventListener(flash.events.Event.COMPLETE, this.initPicHandler);
			loc1.removeEventListener(flash.events.IOErrorEvent.IO_ERROR, this.errorHandler);
			var loc2:*=new flash.display.Loader();
			loc2.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, this.initBMD);
			loc2.loadBytes(loc1.bytes);
			return;
		}
		
		private function initBMD(arg1:flash.events.Event):void
		{
			var loc1:*=arg1.target as flash.display.LoaderInfo;
			loc1.removeEventListener(flash.events.Event.COMPLETE, this.initBMD);
			var loc2:*=loc1.loader as flash.display.Loader;
			var loc3:*;
			(loc3 = new BitmapData(loc2.width, loc2.height)).draw(loc2);
			this.initBmd = loc3;
			loc2.unload();
			return;
		}
		
		private function errorHandler(arg1:flash.events.IOErrorEvent):void
		{
			return;
		}
		
		private var _bmd:BitmapData;
		
		private var _type:int=2;
		
		private var _imgData:ByteArray;
	}
}